package com.smbms.Interceptor;

import com.smbms.pojo.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthorizationInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception{

        User user = (User)request.getSession().getAttribute("userSession");

        if (user==null){
            response.sendRedirect(request.getContextPath()+"/user/401.html");
            return false;
        }
        
        return true;
    }
}
